package com.apps.ftapp.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.apps.ftapp.R;
import com.duobeiyun.bean.ChatBean;


import java.util.List;

public class CusomizeaAdapter extends ArrayAdapter<ChatBean> {
    private int resource;
    private Context context;

    public CusomizeaAdapter(Context context, int resource, List<ChatBean> objects) {
        super(context, resource, objects);
        this.resource = resource;
        this.context = context;
    }

    @Override
    public View getView(int position, View view, ViewGroup parent) {
        ChatBean chatBean = getItem(position);
        ViewHolder viewHolder = null;
        if (view == null) {
            viewHolder = new ViewHolder();
            view = LayoutInflater.from(getContext()).inflate(resource, null, false);
            viewHolder.nickname = view.findViewById(R.id.nickname);
            viewHolder.comment = view.findViewById(R.id.comment);

            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }
        viewHolder.nickname.setText(chatBean.getUsername()+" : ");
        viewHolder.comment.setText(chatBean.getMessage());
        return view;
    }


    private class ViewHolder {
        TextView nickname;
        TextView comment;
    }

}
